package io.yx.flx.entity;

import cn.hutool.json.JSONUtil;
import lombok.Data;

@Data
public class BaseResponse {

    private String code;
    private String msg;
    private Object data;


    private BaseResponse(String code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static String success() {
        BaseResponse baseResponse = new BaseResponse("0000", "success", null);
        return JSONUtil.toJsonStr(baseResponse);
    }

    public static String success(Object data) {
        BaseResponse baseResponse = new BaseResponse("0000", "success", data);
        return JSONUtil.toJsonStr(baseResponse);
    }

    public static String error() {
        BaseResponse baseResponse = new BaseResponse("9999", "error", null);
        return JSONUtil.toJsonStr(baseResponse);
    }

    public static String error(String msg) {
        BaseResponse baseResponse = new BaseResponse("9999", msg, null);
        return JSONUtil.toJsonStr(baseResponse);
    }

    public static String error(String code, String msg) {
        BaseResponse baseResponse = new BaseResponse(code, msg, null);
        return JSONUtil.toJsonStr(baseResponse);
    }

}
